import request from '@/utils/request'

// 查询教学班信息列表
export function listTeachingclass(query) {
  return request({
    url: '/teachingclass/teachingclass/list',
    method: 'get',
    params: query
  })
}

// 查询教学班信息详细
export function getTeachingclass(classId) {
  return request({
    url: '/teachingclass/teachingclass/' + classId,
    method: 'get'
  })
}

// 新增教学班信息
export function addTeachingclass(data) {
  return request({
    url: '/teachingclass/teachingclass',
    method: 'post',
    data: data
  })
}

// 修改教学班信息
export function updateTeachingclass(data) {
  return request({
    url: '/teachingclass/teachingclass',
    method: 'put',
    data: data
  })
}

// 删除教学班信息
export function delTeachingclass(classId) {
  return request({
    url: '/teachingclass/teachingclass/' + classId,
    method: 'delete'
  })
}


export function getTeacherClasses() {
  return request({
    url: '/teachingclass/teachingclass/teacher',
    method: 'get',
    transformResponse: [
      function(data) {
        try {
          return JSON.parse(data) // 直接返回解析后的数据
        } catch (e) {
          console.error('解析响应数据失败:', e)
          return [] // 解析失败时返回空数组
        }
      }
    ]
  })
}

export function getClassStudents(classId) {
  return request({
    url: `/teachingclass/teachingclass/${classId}/students`,
    method: 'get'
  })
}
